package cn.springboot.chatper04error.config;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.web.servlet.error.ErrorViewResolver;
import org.springframework.boot.web.servlet.error.DefaultErrorAttributes;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.WebRequest;

import java.util.Map;

/*@Component*/
public class MyErrorAttribute extends DefaultErrorAttributes {

    @Override
    public Map<String, Object> getErrorAttributes(WebRequest webRequest, boolean includeStackTrace) {
        //获取springboot默认提供的错误信息
        Map<String, Object> errorAttributes=super.getErrorAttributes(webRequest, includeStackTrace);
        errorAttributes.put("custommsg","出错啦");
        errorAttributes.remove("error");
        return errorAttributes;
    }

}
